home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / Overview / System 7.0 Samples / ProcDoggie 1.0a6 / UProcessUtils.p < prev   
Encoding:
Text File  |  1994-11-18  |  10.2 KB  |  252 lines  |  [TEXT/MPS ]

  1. UNIT UProcessUtils;
  2.  
  3. {-------------------------------------------------------------------------------
  4. #
  5. #    Apple Macintosh Developer Technical Support
  6. #
  7. #    Interfaces for the guts of the ProcDoggie application
  8. #
  9. #    Program:    ProcDoggie
  10. #    File:        UProcessUtils.p - Pascal Implementation
  11. #
  12. #    by:        Forrest Tanaka
  13. #
  14. #    Copyright © 1988-1991 Apple Computer, Inc.
  15. #    All rights reserved.
  16. #
  17. --------------------------------------------------------------------------------
  18. #
  19. #    This unit is a high-level interface to the Process Manager.  It contains
  20. #    routines which allow you to launch a process, terminate a process, count the
  21. #    number of open processes, find a process given a file specification, and
  22. #    manage a list of documents for a process to open or print when it is
  23. #    launched.
  24. #
  25. #    The LaunchProcess routine is the most important routine in this unit.  It
  26. #    lets you launch either an application or a desk accessory and optionally lets
  27. #    you pass it a list of documents for the launched application to open or print
  28. #    (desk accessories don’t have document lists).
  29. #
  30. -------------------------------------------------------------------------------}
  31. {[j=20/57/1$] Pasmat Options}
  32.  
  33.  
  34. INTERFACE
  35.  
  36.  
  37. (*******************************************************************************
  38. * Used Units
  39. *******************************************************************************)
  40.  
  41.     USES
  42.         (* Group 1 *)
  43.          Types
  44.         ,QuickDraw
  45.  
  46.         (* Group 2 *)
  47.         ,AppleEvents
  48.         ,Errors
  49.         ,Events
  50.         ,OSUtils
  51.         ,Memory
  52.         ,Resources
  53.         ,SegLoad
  54.  
  55.         (* Group 3 *)
  56.         ,Aliases
  57.         ,Files
  58.         ,Processes
  59.         ,TextUtils
  60.         ;
  61.  
  62.  
  63. (*******************************************************************************
  64. * Types
  65. *******************************************************************************)
  66.  
  67.     TYPE
  68.         (* Flag to indicate whether document list is for printing or opening *)
  69.         LaunchModeCode = (kJustLaunch, kOpenLaunch, kPrintLaunch);
  70.  
  71.         (* Document list entry for opening apps with docs to open or print *)
  72.         DocListEntryPtr = ^DocListEntryRec;
  73.         DocListEntryHnd = ^DocListEntryPtr;
  74.         DocListEntryRec = RECORD
  75.             next:    DocListEntryHnd; {Link to the next document list record}
  76.             docFile: FSSpec           {File specification}
  77.         END;
  78.  
  79.         (* Document list for opening apps with docs to open or print *)
  80.         DocListRec = RECORD
  81.             docList:   DocListEntryHnd; {Handle to the first document list entry}
  82.             openPrint: LaunchModeCode   {Opening or printing documents?}
  83.         END;
  84.         DocListPtr = ^DocListRec;
  85.         DocListHnd = ^DocListPtr;
  86.  
  87.  
  88. (*******************************************************************************
  89. * CreateDocList - Create a new document list
  90. *
  91. * This routine creates a new document list and returns a handle to it.  If there
  92. * isn’t enough memory for a new document list, CreateDocList returns NIL.
  93. *
  94. * If openOrPrint is kOpenLaunch, then the list of documents that are put into
  95. * the new document list will be opened when the application is launched.  If
  96. * openOrPrint is kPrintLaunch, then the list of documents will be printed when
  97. * the application is launched.  If kJustLaunch or any other value is passed in
  98. * openOrPrint, then no document list is created.  CreateDocList returns NIL in
  99. * this case.  This isn’t really a conflict with returning NIL when there’s not
  100. * enough memory for the new document list because the calling routine can check
  101. * to see if openOrPrint is valid or not itself.
  102. *******************************************************************************)
  103.  
  104.     FUNCTION CreateDocList (openOrPrint: LaunchModeCode): DocListHnd;
  105.  
  106.  
  107. (*******************************************************************************
  108. * IsEmptyDocList - Return TRUE if the specified document list is empty.
  109. *
  110. * IsEmptyDocList returns TRUE if the document list specified by "theList" is
  111. * empty.  “Empty” can mean either that theList is NIL or theList is a handle to
  112. * a document list that contains no documents.  It returns FALSE if there’s at
  113. * least one entry in "theList".
  114. *
  115. * theList must either be a valid handle to a document list or it must be NIL.
  116. * IsEmptyDocList is unpredictable if this isn’t true.
  117. *******************************************************************************)
  118.  
  119.     FUNCTION IsEmptyDocList (theList: DocListHnd): Boolean;
  120.  
  121.  
  122. (*******************************************************************************
  123. * AddToDocList - Add a document file specification to a document list
  124. *
  125. * AddToDocList adds the file specified by "newFile" to the end of the document
  126. * list specified by "theList".  If there isn’t enough memory to add a new file
  127. * to the document list, then AddToDocList returns memFullErr.  Otherwise, noErr
  128. * is returned.
  129. *
  130. * theList MUST be a valid handle to an initialized document list.  I won’t be
  131. * responsible for AddToDocList’s actions if this isn’t true.
  132. *******************************************************************************)
  133.  
  134.     FUNCTION AddToDocList (newFile: FSSpec;
  135.                            theList: DocListHnd): OSErr;
  136.  
  137.  
  138. (*******************************************************************************
  139. * DisposeDocList - Dispose of a document list
  140. *
  141. * DisposeDocList deallocates all the memory occupied by the document list
  142. * specified by the "theList" parameter.  If theList is NIL, then nothing is
  143. * done.  If it’s not a valid DocListHnd, DisposeDocList is unpredictable.
  144. *******************************************************************************)
  145.  
  146.     PROCEDURE DisposeDocList (theList: DocListHnd);
  147.  
  148.  
  149. (*******************************************************************************
  150. * WereInFront - Test to see if this application is in front or not
  151. *
  152. * This routine determines whether this application is the front-most application
  153. * or not.  If it is, then TRUE is returned.  If it isn’t, then FALSE is
  154. * returned.
  155. *******************************************************************************)
  156.  
  157.     FUNCTION WereInFront: Boolean;
  158.  
  159.  
  160. (*******************************************************************************
  161. * FindProcess - Find a process with specified file and name
  162. *
  163. * FindProcess searches the Process Manager’s process list for a process that was
  164. * launched from the file specified by "testFile".  If the process being searched
  165. * is a DA, then the "daName" parameter must specify the name of the desk
  166. * accessory (i.e. the name of the DRVR resource, including the initial null
  167. * character).  If the process is found, then information about the process is
  168. * returned in the "testFileInfo" parameter, and FindProcess returns TRUE.  If
  169. * the process could not be found, then FALSE is returned, and "testFileInfo" is
  170. * unchanged.
  171. *
  172. * Warning: the processName and processAppSpec fields of "testFileInfo" are NOT
  173. * valid when FindProcess returns TRUE.  If the name and FSSpec of the found file
  174. * are desired, then the calling routine must allocate space for those fields
  175. * and call GetProcessInfo itself, passing the ProcessInfoRec returned by this
  176. * routine as a parameter.
  177. *******************************************************************************)
  178.  
  179.     FUNCTION FindProcess (testFile:         FSSpec;
  180.                           daName:           StringPtr;
  181.                           VAR testFileInfo: ProcessInfoRec): Boolean;
  182.  
  183.  
  184. (*******************************************************************************
  185. * LaunchProcess - Launch the specified process
  186. *
  187. * This routine launches the process whose file has the location and name
  188. * specified by "processFile" parameter.  The process’s resulting serial number
  189. * is returned in the returnPSN parameter.  If the process to be launched is a
  190. * desk accessory, then the name of the desk accessory (including the initial
  191. * null character that desk accessories require) is passed in daName.  IF NIL is
  192. * passed in daName, then the first desk accessory found in the specified file
  193. * (according to the Resource Manager) is launched.  If an application is being
  194. * launched, then daName is ignored.  The options parameter specifies options to
  195. * use when launching the new process.  It has the same values and meanings as
  196. * the LaunchFlags type defined in the Process Manager chapter of Inside
  197. * Macintosh VI.  If a desk accessory is being launched, then only the
  198. * launchContinue flag has significance.
  199. *
  200. * A list of documents to be opened or printed by the launched application can
  201. * optionally be specified by the docList parameter.  If no documents are
  202. * specified, then docList should be NIL.  See the document list routines defined
  203. * early in this unit.
  204. *
  205. * LaunchProcess determines whether to launch an application or desk accessory
  206. * based on the type code of the file specified by processFile.  If the file’s
  207. * type is APPL, then LaunchProcess attempts to launch it as an application.  If
  208. * the file has any other type, then LaunchProcess attempts to launch a desk
  209. * accessory in that file.
  210. *
  211. * LaunchProcess returns two kinds of errors.  One error is returned as a
  212. * function result.  These kinds of errors are generated by any call that occurs
  213. * during the execution of LaunchProcess that is only used to manage the
  214. * launching of the specified application rather than launching the application
  215. * itself.   The launchError parameter returns the error code of any error that
  216. * occurs when the application is actually launched.
  217. *******************************************************************************)
  218.  
  219.     FUNCTION LaunchProcess (processFile:     FSSpec;
  220.                             daName:          StringPtr;
  221.                             docList:         DocListHnd;
  222.                                     options:         LaunchFlags;
  223.                             VAR returnPSN:   ProcessSerialNumber;
  224.                                     VAR launchError: OSErr): OSErr;
  225.  
  226.  
  227. (*******************************************************************************
  228. * CountProcesses - Count the number of open processes
  229. *
  230. * This routine searches through the Process Manager’s process list and counts
  231. * the number of open processes.  The result is returned.
  232. *******************************************************************************)
  233.  
  234.     FUNCTION CountProcesses: Integer;
  235.  
  236.  
  237. (*******************************************************************************
  238. * TerminateProcess - Terminate a process
  239. *
  240. * This routine causes the process specified by "theProcessNum" to be terminated.
  241. * If an error occurs, then the error code is returned.
  242. *******************************************************************************)
  243.  
  244.     FUNCTION TerminateProcess (theProcessNum: ProcessSerialNumber): OSErr;
  245.  
  246.  
  247. IMPLEMENTATION
  248.  
  249.     {$I UProcessUtils.inc1.p}
  250.  
  251. END.
  252.